package com.producer.spring_producer.producer;

import com.producer.spring_producer.entity.Order;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author yy
 * @date 2019/10/29 23:45
 **/
@Component
public class OrderSender {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void send(Order order) throws Exception {

        CorrelationData correlationData = new CorrelationData();
        correlationData.setId(order.getMessageId());

        rabbitTemplate.convertAndSend("order-exchange", // exchange
                "order.abcd", // routingKey
                order, // object 消息体内容
                correlationData // correlationData 消息唯一ID
        );

    }

}
